﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class StringHandler
{
    /// <summary>
    /// 将xml传入后的内容用转义字符成所需的内容
    /// </summary>
    /// <param name="preStr"></param>
    /// <param name="marryRule"></param>
    /// <param name="param"></param>
    /// <returns></returns>
    public static string strReplaceHandler(string preStr,string marryRule, List<string> param)
    {
        string retString = preStr;

        Regex rgx = new Regex(marryRule);

        int matchCount = rgx.Matches(preStr).Count; // 匹配到的个数

        for (int i = 0; i < matchCount; i++ )
        {
            if (param.Count > i)// 如果传入的替换参数个数大于所需要替换的原始数据个数，则进行替换
            {
                retString = rgx.Replace(retString, param[i], 1);
            }
            else
            {
                retString = rgx.Replace(retString, "曹建华", 1);
            }
        }

        // 实现递归

        return retString;
    }

    public static string getProperties<T>(T t)
    {
        string tStr = string.Empty;
        if (t == null)
        {
            return tStr;
        }
        System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

        if (properties.Length <= 0)
        {
            return tStr;
        }
        foreach (System.Reflection.PropertyInfo item in properties)
        {
            string name = item.Name;
            object value = item.GetValue(t, null);
            if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
            {
                tStr += string.Format("{0}:{1},", name, value);
            }
            else
            {
                getProperties(value);
            }
        }
        return tStr;
    }

    // 金币字符串处理，如 k,bl 1,230,000=>1.23 mil
    string moneyStringHander(string str)
    {
        return null;
    }

    //  
    string timeStringHander()
    {

        return null;
    }

}
